package StackAndQueue;

import java.util.LinkedList;
import java.util.Queue;

class MyStack {
    Queue<Integer> in;
    Queue<Integer> out;

    public MyStack() {
        in = new LinkedList<>();
        out = new LinkedList<>();
    }
    
    public void push(int x) {
        while (!in.isEmpty()) {
            out.add(in.poll());
        }
        in.add(x);
        while (!out.isEmpty()) {
            in.add(out.poll());
        }
    }
    
    public int pop() {
        return in.remove();
    }
    
    public int top() {
        return in.element();
    }
    
    public boolean empty() {
        return in.isEmpty();
    }

}